import Vue from 'vue'
import VueRouter from 'vue-router'

const home = r => require.ensure([], () => r(require('@/views/home/index.vue')), 'home');
const pageHome = r => require.ensure([], () => r(require('@/views/page/index.vue')), 'pageHome');
const workMain = r => require.ensure([], () => r(require('@/views/works/main.vue')), 'workMain');
const workList = r => require.ensure([], () => r(require('@/views/works/list.vue')), 'workList');
const workOther = r => require.ensure([], () => r(require('@/views/works/other.vue')), 'workOther');
const workDetail = r => require.ensure([], () => r(require('@/views/works/detail.vue')), 'workDetail');
const innovateMain = r => require.ensure([], () => r(require('@/views/innovate/main.vue')), 'innovateMain');
const innovateList = r => require.ensure([], () => r(require('@/views/innovate/list.vue')), 'innovateList');
const innovateOther = r => require.ensure([], () => r(require('@/views/innovate/other.vue')), 'innovateOther');
const innovateDetail = r => require.ensure([], () => r(require('@/views/innovate/detail.vue')), 'innovateDetail');
const designer = r => require.ensure([], () => r(require('@/views/designer/index.vue')), 'designer');
const info = r => require.ensure([], () => r(require('@/views/info/index.vue')), 'info');
const department = r => require.ensure([], () => r(require('@/views/department/index.vue')), 'department');

const routes = [
    {
        path: '/',
        component: home
    },
    {
        path: '/home/:date?',
        component: home
    },
    {
        path: '/pageHome',
        component: pageHome,
        children:[
            {
                path:'/works/main/:id?',
                component:workMain
            },
            {
                path:'/works/list/:id?',
                component:workList
            },
            {
                path:'/works/other/:id?',
                component:workOther
            },
            {
                path:'/innovate/main/:id?',
                component:innovateMain
            },
            {
                path:'/innovate/list/:id?',
                component:innovateList
            },
            {
                path:'/innovate/other/:id?',
                component:innovateOther
            },
            {
                path:'/designer/:id?',
                component:designer
            },
            {
                path:'/info/:id?',
                component:info
            },
            {
                path:'/department/:id?',
                component:department
            }
        ]
    },
    {
        path: '/works/detail/:id',
        component: workDetail
    },
    {
        path: '/innovate/detail/:id',
        component: innovateDetail
    }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const router = new VueRouter({
    routes
})

export default router
